<template>
	<BasicModal v-bind="$attrs" z-index="1000" style="z-index:1000" @register="registerModal" title="选择类别"
		@ok="confirmActivitySelect">
		<!-- 表格管理数据，这里直接新增、修改、删除 -->
		<a-row>
			<a-col :span="24">
				<BasicTree :treeData="treeData" :checkable="true" defaultExpandAll @check="handleCheck" />
			</a-col>
		</a-row>

	</BasicModal>
</template>
<script lang="ts" setup>
	import { BasicTree } from '/@/components/Tree/index';
	import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
	import { defineComponent, ref, watch, inject, unref } from 'vue';
	import { activityList } from '../BsActiveItem.api'
	const checkedKeys1 = ref([] as array)
	const emit = defineEmits(['register', 'successConfirm']);
	const treeData = ref([] as Array);
	checkedKeys1.value = []
	const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
		getShelfList()
	})

	async function getShelfList() {
		let ls = await activityList({})
		let o = {}, os = [], children = [], childreno = {}
		for (var i = 0; i < ls.length; i++) {
			o = {}
			o.title = ls[i].gtitle
			children = []
			if (ls[i].typeCode) {
				for (var j = 0; j < ls[i].typeCode.length; j++) {
					childreno = {}
					childreno.title = ls[i].typeCode[j].title
					childreno.key = ls[i].typeCode[j].code
					children.push(childreno)
				}
			}

			o.children = children
			os.push(o)
		}
		treeData.value = os

	}
	function handleCheck(checkedKeys, e) {
		checkedKeys1.value = checkedKeys
	}
	function confirmActivitySelect() {
		let os = []
		let ls = treeData.value
		for (var i = 0; i < ls.length; i++) {
			if (ls[i].children) {
				for (var j = 0; j < ls[i].children.length; j++) {
					for (var k = 0; k < checkedKeys1.value.length; k++) {
						if (checkedKeys1.value[k] == ls[i].children[j].key) {
							os.push(ls[i].children[j])
						}
					}
				}
			}
		}
		emit("successConfirm", os)
		closeModal();

	}
</script>

<style lang="less" scoped>

</style>